package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Candidate;
import com.skyolder.milkbee.repository.CandidateRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * Service Implementation for managing Candidate.
 */
@Service
@Transactional
public class CandidateService {

    private final Logger log = LoggerFactory.getLogger(CandidateService.class);
    
    @Inject
    private CandidateRepository candidateRepository;

    /**
     * Save a candidate.
     *
     * @param candidate the entity to save
     * @return the persisted entity
     */
    public Candidate save(Candidate candidate) {
        log.debug("Request to save Candidate : {}", candidate);
        Candidate result = candidateRepository.save(candidate);
        return result;
    }

    /**
     *  Get all the candidates.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<Candidate> findAll(Pageable pageable) {
        log.debug("Request to get all Candidates");
        Page<Candidate> result = candidateRepository.findAll(pageable);
        return result;
    }

    /**
     *  Get one candidate by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public Candidate findOne(Long id) {
        log.debug("Request to get Candidate : {}", id);
        Candidate candidate = candidateRepository.findOne(id);
        return candidate;
    }

    /**
     *  Delete the  candidate by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Candidate : {}", id);
        candidateRepository.delete(id);
    }

	public void deleteByQuestionnaireId(Long questionnaireId) {
		candidateRepository.deleteByQuestionnaireId(questionnaireId);
	}

	public List<Candidate> findByQuestionnaireIdIn(List<Long> ids) {
		return candidateRepository.findByQuestionnaireIdIn(ids);
	}

	public List<Candidate> findByQuestionnaireId(Long questionnaireId) {
		return candidateRepository.findByQuestionnaireId(questionnaireId);
	}
}
